<%@ page import="com.zx.mobile.domain.MobileUserDomain" %>
<%@ page import="com.zx.mobile.SessionHelper" %>
<!doctype html>
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"
         language="java" %>
<%@ include file="/jsp/mobile/include/include.jsp" %>
<html lang="cn">
<head>
    <%@ include file="/jsp/mobile/include/header.jsp" %>
    <title>添加信用卡</title>
</head>
<body>
<div class="main">
    <div class="ciTab">
        <ul>
            <input type="hidden" id="bankCode" name="bankCode" value="${model.bankCode}"/>
            <input type="hidden" id="bankName" name="bankName" value="${model.bankName}"/>
            <input type="hidden" id="notifyFlag" name="notifyFlag" value="1"/>
            <input type="hidden" id="notifyDate" name="notifyDate" value="${model.notifyDate}"/>
            <li>
                <span class="tit">持卡人</span>
                <input id="cardName" name="cardName"
                       value="<c:out value="${_MOBILEUSER_.merchantInfoDetailModel.legalName}" />" type="text"
                       class="text" placeholder="输入持卡人姓名" readonly>
            </li>
            <li id="banklist">
                <span class="tit">发卡行</span><span style="font-size: 14px;"><c:out value="${model.bankName}"/></span>
                <i class="ico ico16"></i>
            </li>
            <li>
                <span class="tit">卡号</span>
                <input id="cardNo" name="cardNo" type="number" class="text" value="<c:out value="${model.cardNo}"/>" placeholder="输入14-16位数字">
            </li>
        </ul>
    </div>
    <div class="ciTab mt15">
        <ul>
            <li id="notifyFlagI">
                           <span class="tit">还款提醒</span>
                           <i class="ico ico44"></i>
                       </li>
            <li id="notifyDaylist">
                <span class="tit">提醒日期</span>
                <span style="font-size: 14px;">
                    每月<c:out value="${model.notifyDate}"/>号
                		</span>
                <i class="ico ico16"></i>
            </li>
        </ul>
    </div>
    <div class="payOk">
        <div class="nbtn mt20">
            <a class="butn" href="#" onclick="submit();">确认</a>
        </div>
    </div>
</div>
<div class="tspb" style="display:none">
    <i class="ico ico46 mr5"></i>添加成功
</div>
<form action="" id="linkForm" method="post"></form>
<script type="text/javascript">
    $("#banklist").bind("click", function () {
        $("#linkForm").attr("action", "<%=request.getContextPath()%>/mobile/index/supportCreditList?notifyDate=" + $("#notifyDate").val()+"&cardNo="+$("#cardNo").val());
        $("#linkForm").submit();
    });
    $("#notifyDaylist").bind("click", function () {
        $("#linkForm").attr("action", "<%=request.getContextPath()%>/mobile/index/supportNotifyDayList?bankCode=" + $("#bankCode").val() + "&bankName=" + $("#bankName").val()+"&cardNo="+$("#cardNo").val());
        $("#linkForm").submit();
    });
    //切换是否提醒
    $("#notifyFlagI i").bind("click", function () {
        var _i = $(this);
        if (_i.hasClass('ico44')) {
            _i.removeClass("ico44").addClass("ico45");
            $("#notifyFlag").val("0");
        } else {
            _i.removeClass("ico45").addClass("ico44");
            $("#notifyFlag").val("1");
        }
    });

    function submit() {
        var _bankCode = $("#bankCode").val().trim();
        var _notifyFlag = $("#notifyFlag").val().trim();
        var _notifyDate = $("#notifyDate").val().trim();
        var _cardNo = $("#cardNo").val().trim();
        var _cardName = $("#cardName").val().trim();
        var _msg = "";
        if (_bankCode == '') {
            _msg += "选择银行\r\n";
        }
        if (_notifyFlag == '') {
            _msg += "设置是否提醒\r\n";
        }
        if (_notifyDate == '') {
            _msg += "选择提醒日期\r\n";
        }
        if (_cardNo == '') {
            _msg += "输入信用卡卡号\r\n";
        } else if (!cardNoCheck(_cardNo)) {
            _msg += "信用卡卡号不正确\r\n";
        }
        if (_cardName == '') {
            _msg += "输入持卡人姓名\r\n";
        }
        if (_msg == "") {
            $.ajax({
                type: "GET",
                url: "<%=request.getContextPath()%>/mobile/index/addCreditCard",
                data: {
                    'bankCode': _bankCode,
                    'notifyFlag': _notifyFlag,
                    'notifyDate': _notifyDate,
                    'cardNo': _cardNo,
                    'cardName': _cardName,
                    'bankName': $("#bankName").val()
                },
                dataType: "json",
                success: function (msg) {
                    if (msg.success) {
                        window.location.href = "<%=request.getContextPath()%>/mobile/index/creditRepay";
                    } else {
                        window.openMsg(msg.msg, 3);
                    }
                }
            });
        }
        else {
            window.openMsg(_msg, 3);
        }
    }
</script>
</body>
</html>